package cn.doctor.assistant.pad.api.zhuye;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;

import cn.doctor.assistant.pad.MyApplication;
import cn.doctor.assistant.pad.api.bean.AssResponse;
import cn.doctor.assistant.pad.api.AssistAPI;
import cn.doctor.assistant.pad.api.bean.ReqBean;
import cn.doctor.assistant.pad.base.AssJsonRequest;
import cn.doctor.assistant.pad.base.ResultCallback;

/**
 * Created by jiaolf on 2016/3/24.
 * 主页
 */
public class HomeApi {

    public static final String METHOD_GET_NOTICE = "GetNotice";

    public static void getNotice(final ResultCallback<GetNoticeResponse> callback) {
        String org_id = MyApplication.getInstance().mDoctors.get(0).getOrg_id()+"";
        GetNoticeRequest request = new GetNoticeRequest();
        request.setOrg_id(org_id);

        ReqBean reqBean = ReqBean.newInstance(METHOD_GET_NOTICE, request);
        String jsonStrParams = JSON.toJSONString(reqBean);

        AssJsonRequest jsonRequest = new AssJsonRequest(jsonStrParams, new Response.Listener<String>(){

            @Override
            public void onResponse(String result) {
                Log.d("jzsn", result);
                AssResponse resp = JSON.parseObject(result, AssResponse.class);
                if (resp.isSuccess()) {
                    GetNoticeResponse noticeResponse = JSON.parseObject(resp.getResult().getData(), GetNoticeResponse.class);
                    callback.onSuccess(noticeResponse);
                }else {
                    callback.onFail("获取失败:"+resp.getResult().getInfo());
                }
            }
        });

        jsonRequest.setTag(METHOD_GET_NOTICE);
        AssistAPI.getRequestQueue().add(jsonRequest);
    }
}
